$(function () {
//    $("#_qyjg").qyjgzcombobox();
//    $("#qyjg").qyjgzcombobox();
    //页面初始加载
    var type = $("#qyjg_toolbar input[name='query_type']:checked").val(); //获取初始页面加载值
    $('#qyjg_grid').datagrid({
        url: $.webPath() + "/organ/qyjg/qyjgList?type=" + type,
        toolbar: "#qyjg_toolbar",
        fitColumns: true,
        singleSelect: true,
        pageNumber: 1,
        pagination: true,
        fit: true,
        rownumbers: "true",
        columns: [
            [
                {field: 'qc', title: '全称', width: 50},
                {field: 'jc', title: '简称', width: 30},
                {field: 'qyfr_qyqc', title: '企业法人', width: 40},
                {field: 'lxr', title: '联系人', width: 30},
                {field: 'lxdh', title: '联系电话', width: 30},
                {field: 'bzjfs', title: '保证金使用方式', width: 30,
                    formatter: function (value) {
                        if (value == '0')
                            return '一次性使用';
                        if (value == '1')
                            return '按比例使用';
                        if (value == '2')
                            return '无保证金';
                    }
                },
                {field: 'bm', title: '编码', width: 30},
//                {field: 'bz', title: '备注', width: 60},
                {field: 'zt', title: '状态', width: 30, formatter: formatQyjgSp},
                {field: 'sfzx', title: '启用', align: 'center', width: 10, formatter: function (value) {
                    if (value == '是')
                        return '否';
                    else
                        return '是';
                }}
            ]
        ],
        onLoadSuccess: function () {
            $("#qyjg_mod").hide();
            $("#qyjg_del").hide();
            $("#qyjg_commit").hide();
            $("#qyjg_start").hide();
            $("#qyjg_gl").hide();
            $("#qyjg_qxgl").hide();
            $("#qyjg_nbgs").hide();
        },
        loadFilter: function (data) {
            $.each(data.rows, function () {
                if (this.zt) {
                    this.zt = this.zt == 'ysp' ? "已审批" : this.zt == 'ytj' ? "已提交" : "已保存";
                }
            })
            return data;
        },
        onClickRow: function (rowIndex, rowData) {
            $("#qyjg_mod").show();
            $("#qyjg_del").show();
            $("#qyjg_gl").show();
            $("#qyjg_qxgl").show();
            if (rowData.zt == '已保存') {
                $("#qyjg_commit").show();
            } else if (rowData.zt == '已审批') {
                if (rowData.sfzx == null || rowData.sfzx == '是') {
                    $("#qyjg_start").text('启用');
                    $("#qyjg_mod").show();
                    $("#qyjg_start").removeClass('stop').addClass('start');
                    $('#qyjg_start').unbind('click');
                    $('#qyjg_start').bind('click', function () {
                        changeQyjgState($.webPath() + '/organ/qyjg/start_qyjg', '确认启用此机构？');
                    });
                } else {
                    $("#qyjg_start").text('停用');
                    $("#qyjg_mod").hide();
                    $("#qyjg_start").removeClass('start').addClass('stop');
                    $('#qyjg_start').unbind('click');
                    $('#qyjg_start').bind('click', function () {
                        changeQyjgState($.webPath() + '/organ/qyjg/stop_qyjg', '确认停用此机构？');
                    });
                }
                $("#qyjg_del").hide();
                $("#qyjg_start").show();
                $("#qyjg_nbgs").show();
                $('#qyjg_nbgs').unbind('click');
                $('#qyjg_nbgs').bind('click', function () {
                    changeQyjgNbgs($.webPath() + '/organ/qyjg/qyjg_nbgs', '确认设置此机构为内部公司？');
                });
            } else {
                $("#qyjg_commit").hide();
                $("#qyjg_del").hide();
                $("#qyjg_mod").hide();
                $("#qyjg_nbgs").hide();
            }

        },
      /*  onDblClickCell: function (rowIndex, field) {
            if (field == "qc")
                $("#qyjg_mod:visible").click();
//                qyjg_modifyItem();
        },*/
        rowStyler: function (index, row) {
            if (row.sfzx == '是') {
                return 'background-color:rgba(255, 130, 87, 0.64);';
            }
        }
    });
    //当类型切换时切换页面
    $("#qyjg_toolbar input[name='query_type']").change(function () {
//        $('#qyjg').combotree('clear');
//        $('#_qyjg').combotree('clear');
//        $('#qyjg_lxr').combobox('clear');
        var type = $("#qyjg_toolbar input[name='query_type']:checked").val();
//        $('#qyjg').combotree('reload', $.webPath() + "/organ/qyjg/qyjgjc_tree?type=" + type);
//        $('#_qyjg').combotree('reload', $.webPath() + "/organ/qyjg/qyjg_tree?type=" + type);
//        $('#qyjg_lxr').combobox('reload', $.webPath() + "/organ/qyjg/qyjgLxrList?type=" + type);
        qyjg_search();
    });
    //**************按钮绑定事件*************
    //搜索按钮触发
    $('#qyjg_search').click(
        qyjg_search
    );

    //企业机构导出
    $("#qyjg_dc").click(function () {
        window.open($.webPath() + "/organ/qyjg/qyjg_export");
    });

    //页面新增按钮触发
    $('#qyjg_add').click(
        qyjg_newItem
    );
    //删除按钮触发
    $('#qyjg_del').click(
        qyjg_deleteItem
    );

    $('#qyjg_commit').click(
        qyjg_commit
    );
    //修改按钮触发
    $('#qyjg_mod').click(
        qyjg_modifyItem
    );

    $("#qyjg_fkfs").click(
        function () {
            qyjg_fkfs("维护标准")
        }
    )

    //启用按钮触发
    $("#qyjg_start").click(function () {
        changeQyjgState();
    });

    //**************按钮绑定事件*************


});

var qyjgWin;
//新建弹出框
function qyjg_newItem() {
    var type = $("#qyjg_toolbar input[name='query_type']:checked").val();
    if (type == 1) {
        var title = '新增企物流商';
        var url = $.webPath() + '/organ/qyjg/qyjg_content?type=' + type;
    } else {
        var title = '新增企业机构';
        var url = $.webPath() + '/organ/qyjg/qyjg_content?type=' + type;
    }
    qyjgWin = $.window({
        onBeforeClose: function () {
            $(".validatebox-tip").remove();
        },
        title: title,
        width: 600,
        height: 420,
        cache: false,
        iconCls: 'icon-add2',
        url: url,
        modal: true,
        buttons: [
            {
                text: '保存',
                handler: function () {
                    var type = $("#qyjg_type input[name='type']:checked").val();
                    var selector;
                    if (type == 0) {
                        selector = "#qyjgForm";
                    } else {
                        selector = "#wlsForm";
                    }
                    var valid = $(selector).form('validate');
                    if (valid) {
                        qyjg_saveItem();
                    } else {
                        $.messager.progress('close');
                        var r = $('#qyjgForm #nbjg_grid').edatagrid("getSelected");
                        var index = $('#qyjgForm #nbjg_grid').edatagrid("getRowIndex", r);
                        var vald = $('#nbjg_grid').datagrid('validateRow', index);
                        if (vald) {
                            $("#qyjgForm .tabs-title :eq(0)").click();
                        } else {
                            $("#qyjgForm .tabs-title :eq(1)").click();
                        }
                        return;
                    }

                }
            }
        ]
    });
}
//修改弹出框
function qyjg_modifyItem() {
    var type = $("#qyjg_toolbar input[name='query_type']:checked").val();
    var qyjgId = $("#qyjg_grid").datagrid("getSelected").id;
    if (qyjgId) {
        if (type == 1) {
            var title = '修改物流商';
            var url = $.webPath() + '/organ/qyjg/qyjg_content?operation=update&qyjgId=' + qyjgId;
            $('#qyjg_checked').attr('disabled', true);
        } else {
            var title = '修改企业机构';
            var url = $.webPath() + '/organ/qyjg/qyjg_content?operation=update&qyjgId=' + qyjgId;
            $('#wls_checked').attr('disabled', true);
        }
        qyjgWin = $.window({
            onBeforeClose: function () {
                $(".validatebox-tip").remove();
            },
            title: title,
            width: 590,
            height: 490,
            closed: false,
            cache: false,
            iconCls: 'icon-edit',
            url: url,
            modal: true,
            buttons: [
                {
                    text: '保存',
                    handler: function () {
                        var type = $("#qyjg_type input[name='type']:checked").val();
                        var selector;
                        if (type == 0) {
                            selector = "#qyjgForm";
                        } else {
                            selector = "#wlsForm";
                        }
                        var valid = $(selector).form('validate');
                        if (valid) {
                            qyjg_saveUpdateItem();
                        } else {
                            $.messager.progress('close');
                            var r = $('#qyjgForm #nbjg_grid').edatagrid("getSelected");
                            var index = $('#qyjgForm #nbjg_grid').edatagrid("getRowIndex", r);
                            var vald = $('#nbjg_grid').datagrid('validateRow', index);
                            if (vald) {
                                $("#qyjgForm .tabs-title :eq(0)").click();
                            } else {
                                $("#qyjgForm .tabs-title :eq(1)").click();
                            }
                            return;
                        }

                    }
                }
            ]
        });
    }
}
//新增保存
function qyjg_saveItem() {
    var type = $("#qyjg_type input[name='type']:checked").val();
    var selector;
    if (type == 0) {
        selector = "#qyjgForm";
        url = $.webPath() + '/organ/qyjg/add_qyjg';
        $('#nbjg_grid').datagrid('acceptChanges');
        var nbjgRows = $('#nbjg_grid').datagrid('getRows');
        if (nbjgRows != null) {
            //收集部门维护的信息在qyjgForm表单添加隐藏域
            $('#qyjgForm').remove("[name='nbjg.qc']");
            $('#qyjgForm').remove("[name='nbjg.jc']");
            $('#qyjgForm').remove("[name='nbjg.bm']");
            $('#qyjgForm').remove("[name='nbjg.zjm']");
            $('#qyjgForm').remove("[name='nbjg.bz']");
            $.each(nbjgRows, function (i, val) {
                $('#qyjgForm').append('<input name="qyjg.gsjgList[' + i + '].qc" type="hidden" value="' + val.qc + '"/>');
                $('#qyjgForm').append('<input name="qyjg.gsjgList[' + i + '].jc" type="hidden" value="' + val.jc + '"/>');
                $('#qyjgForm').append('<input name="qyjg.gsjgList[' + i + '].bm" type="hidden" value="' + val.bm + '"/>');
                $('#qyjgForm').append('<input name="qyjg.gsjgList[' + i + '].zjm" type="hidden" value="' + val.zjm + '"/>');
                $('#qyjgForm').append('<input name="qyjg.gsjgList[' + i + '].bz" type="hidden" value="' + val.bz + '"/>');
            })
        }
    } else if (type == 1) {
        selector = "#wlsForm";
        url = $.webPath() + '/organ/wls/add_wls';
        /*    $('#ysgj_grid').datagrid('acceptChanges');
         var rows = $('#ysgj_grid').datagrid('getRows');
         if (rows != null) {
         $('#wlsForm').remove("[name='ysgj.ysgjlx.z']");
         $('#wlsForm').remove("[name='ysgj.gps']");
         $('#wlsForm').remove("[name='ysgj.ysgjsbm']");
         $('#wlsForm').remove("[name='ysgj.xm']");
         $('#wlsForm').remove("[name='ysgj.sjhm']");
         $.each(rows, function (i, val) {
         $('#wlsForm').append('<input name="wls.ysgjList[' + i + '].ysgjlx.z" type="hidden" value="' + val.ysgjlx_z + '"/>');
         $('#wlsForm').append('<input name="wls.ysgjList[' + i + '].ysgjsbm" type="hidden" value="' + val.ysgjsbm + '"/>');
         $('#wlsForm').append('<input name="wls.ysgjList[' + i + '].gps" type="hidden" value="' + val.gps + '"/>');
         $('#wlsForm').append('<input name="wls.ysgjList[' + i + '].xm" type="hidden" value="' + val.xm + '"/>');
         $('#wlsForm').append('<input name="wls.ysgjList[' + i + '].sjhm" type="hidden" value="' + val.sjhm + '"/>');
         })
         }
         */
    }
    $(selector).form('submit', {
        url: url,
        onSubmit: function () {
            var isValid = $(this).form('validate');
            if (!isValid) {
                $.messager.progress('close');
            }
            return isValid;
        },
        success: function (data) {
            var obj = eval('(' + data + ')');
            if (obj.statusCode == 200) {
                $(qyjgWin).window("close");
                $('#qyjg_grid').datagrid('reload');
                //$('#_qyjg').combotree('clear');
                // $('#qyjg_lxr').combobox('clear');
                //$("#_qyjg").combotree("reload", $.webPath() + "/organ/qyjg/qyjg_tree?type=" + type);
                //$('#qyjg_lxr').combobox('reload', $.webPath() + "/organ/qyjg/qyjgLxrList?type=" + type);
            } else {
                alert(obj.message);
            }
        }
    });
}
//保存弹出框
function qyjg_saveUpdateItem() {
    var type = $("#qyjg_type input[name='type']:checked").val();
    var qyjgId = $("#qyjg_grid").datagrid("getSelected").id;
    var selector;
    if (type == 0) {
        selector = "#qyjgForm";
        url = $.webPath() + '/organ/qyjg/update_qyjg?qyjgId=' + qyjgId;
        $('#nbjg_grid').datagrid('acceptChanges');
        var nbjgRows = $('#nbjg_grid').datagrid('getRows');
        if (nbjgRows != null) {
            //收集部门维护的信息在qyjgForm表单添加隐藏域
            $('#qyjgForm').remove("[name='nbjg.id']");
            $('#qyjgForm').remove("[name='nbjg.qc']");
            $('#qyjgForm').remove("[name='nbjg.jc']");
            $('#qyjgForm').remove("[name='nbjg.bm']");
            $('#qyjgForm').remove("[name='nbjg.zjm']");
            $('#qyjgForm').remove("[name='nbjg.bz']");
            $.each(nbjgRows, function (i, val) {
                $('#qyjgForm').append('<input name="qyjg.gsjgList[' + i + '].id" type="hidden" value="' + val.id + '"/>');
                $('#qyjgForm').append('<input name="qyjg.gsjgList[' + i + '].qc" type="hidden" value="' + val.qc + '"/>');
                $('#qyjgForm').append('<input name="qyjg.gsjgList[' + i + '].jc" type="hidden" value="' + val.jc + '"/>');
                $('#qyjgForm').append('<input name="qyjg.gsjgList[' + i + '].bm" type="hidden" value="' + val.bm + '"/>');
                $('#qyjgForm').append('<input name="qyjg.gsjgList[' + i + '].zjm" type="hidden" value="' + val.zjm + '"/>');
                $('#qyjgForm').append('<input name="qyjg.gsjgList[' + i + '].bz" type="hidden" value="' + val.bz + '"/>');
            })
        }
    } else if (type == 1) {
        selector = "#wlsForm";
        url = $.webPath() + '/organ/wls/update_wls?wlsId=' + qyjgId;
        /*$('#ysgj_grid').datagrid('acceptChanges');
         var rows = $('#ysgj_grid').datagrid('getRows');
         if (rows != null) {
         //收集运输工具的信息在wlsForm表单添加隐藏域
         $('#wlsForm').remove("[name='ysgj.id']");
         $('#wlsForm').remove("[name='ysgj.ysgjlx.z']");
         $('#wlsForm').remove("[name='ysgj.gps']");
         $('#wlsForm').remove("[name='ysgj.ysgjsbm']");
         $('#wlsForm').remove("[name='ysgj.xm']");
         $('#wlsForm').remove("[name='ysgj.sjhm']");
         $.each(rows, function (i, val) {
         $('#wlsForm').append('<input name="wls.ysgjList[' + i + '].id" type="hidden" value="' + val.id + '"/>');
         $('#wlsForm').append('<input name="wls.ysgjList[' + i + '].ysgjlx.z" type="hidden" value="' + val.ysgjlx_z + '"/>');
         $('#wlsForm').append('<input name="wls.ysgjList[' + i + '].ysgjsbm" type="hidden" value="' + val.ysgjsbm + '"/>');
         $('#wlsForm').append('<input name="wls.ysgjList[' + i + '].gps" type="hidden" value="' + val.gps + '"/>');
         $('#wlsForm').append('<input name="wls.ysgjList[' + i + '].xm" type="hidden" value="' + val.xm + '"/>');
         $('#wlsForm').append('<input name="wls.ysgjList[' + i + '].sjhm" type="hidden" value="' + val.sjhm + '"/>');
         })
         }*/
    }
    $(selector).form('submit', {
        url: url,
        onSubmit: function () {
            var isValid = $(this).form('validate');
            if (!isValid) {
                $.messager.progress('close');
            }
            return isValid;
        },
        success: function (data) {
            var obj = eval('(' + data + ')');
            if (obj.statusCode == 200) {
                $(qyjgWin).window("close");
                $('#qyjg_grid').datagrid('reload');
                //$('#_qyjg').combotree('clear');
                //$('#qyjg_lxr').combobox('clear');
                //$("#_qyjg").combotree("reload", $.webPath() + "/organ/qyjg/qyjg_tree?type=" + type);
                //  $('#qyjg_lxr').combobox('reload', $.webPath() + "/organ/qyjg/qyjgLxrList?type=" + type);
            } else {
                alert(obj.message);
            }
        }
    });
}
//删除企业机构
function qyjg_deleteItem() {
    var qyjgId = $("#qyjg_grid").datagrid("getSelected").id;
    var type = $("#qyjg_toolbar input[name='query_type']:checked").val();
    if (qyjgId) {
        if (type == 1) {
            var url = $.webPath() + "/organ/wls/delete_wls?wlsId=" + qyjgId;
            var message = "是否确认删除此物流商";
        } else {
            var url = $.webPath() + "/organ/qyjg/delete_qyjg?qyjgId=" + qyjgId;
            var message = "是否确认删除此企业机构";

        }
        $.messager.confirm('确认', message, function (r) {
            if (r) {
                $.post(url, {}, function (data) {
                    if (data.statusCode == 200) {
                        $.messager.show({
                            title: '提示框',
                            msg: data.message,
                            timeout: 3000,
                            showType: 'slide'
                        });
                        $('#qyjg_grid').datagrid('reload');
                    } else {
                        $.messager.alert('提示', data.message, 'info');
                    }
                })
            }
        });
    }
}

function qyjg_commit() {
    var qyjgId = $("#qyjg_grid").datagrid("getSelected").id;
    $.messager.confirm('确认', '是否确认提交此企业机构', function (r) {
        if (r) {
            $.post($.webPath() + '/organ/qyjg/commit_qyjg', {qyjgId: qyjgId}, function (data) {
                var obj = eval('(' + data + ')');
                if (obj.statusCode == '200') {
                    $('#qyjg_grid').datagrid('reload');
                    $.messager.show({title: '提示框', msg: obj.message, timeout: 3000, showType: 'slide'});
                } else
                    $.messager.alert('提示', obj.message, 'info');
            });
        }
    });
}
//查询企业机构
function qyjg_search() {
    var type = $("#qyjg_toolbar input[name='query_type']:checked").val();
    var nText1 = $('#qyjg').val() == null ? null : $('#qyjg').val();
    var nText = $('#_qyjg').val() == null ? null : $('#_qyjg').val();
    //var lxrText = $('#qyjg_lxr').combobox('getText') == null ? null : $('#qyjg_lxr').combobox('getText');
    var options = $.extend(getQyjgGridOption(type),
        {queryParams: {type: type, qc: nText, jc: nText1}});
    $('#qyjg_grid').datagrid(options);
}
//页面切换的内容
function getQyjgGridOption(type) {
    var options = {
        url: $.webPath() + "/organ/qyjg/qyjgList",
        toolbar: "#qyjg_toolbar",
        fitColumns: true,
        singleSelect: true,
        pagination: true,
        pageNumber: 1,
        fit: true,
        rownumbers: "true",
        onLoadSuccess: function () {
            $("#qyjg_mod").hide();
            $("#qyjg_del").hide();
            $("#qyjg_start").hide();
            $("#qyjg_gl").hide();
            $("#qyjg_qxgl").hide();
        },
        loadFilter: function (data) {
            $.each(data.rows, function () {
                if (this.zt) {
                    this.zt = this.zt == 'ysp' ? "已审批" : this.zt == 'ytj' ? "已提交" : "已保存";
                }
            })
            return data;
        },
        onClickRow: function (rowIndex, rowData) {
            $("#qyjg_mod").show();
            $("#qyjg_del").show();
            $("#qyjg_gl").show();
            $("#qyjg_qxgl").show();
            if (rowData.zt == '已保存') {
                $("#qyjg_commit").show();
            } else if (rowData.zt == '已审批') {
                if (rowData.sfzx == null || rowData.sfzx == '是') {
                    $("#qyjg_start").text('启用');
                    $("#qyjg_start").removeClass('stop').addClass('start');
                    $('#qyjg_start').unbind('click');
                    $('#qyjg_start').bind('click', function () {
                        changeQyjgState($.webPath() + '/organ/qyjg/start_qyjg', '确认启用此机构？');
                    });
                } else {
                    $("#qyjg_start").text('停用');
                    $("#qyjg_start").removeClass('start').addClass('stop');
                    $('#qyjg_start').unbind('click');
                    $('#qyjg_start').bind('click', function () {
                        changeQyjgState($.webPath() + '/organ/qyjg/stop_qyjg', '确认停用此机构？');
                    });
                }
                $("#qyjg_del").hide();
                $("#qyjg_mod").hide();
                $("#qyjg_start").show();

            } else {
                $("#qyjg_commit").hide();
                $("#qyjg_del").hide();
                $("#qyjg_mod").hide();
            }
        },
        onDblClickCell: function (rowIndex, field, value) {
            if (field == "qc")
                qyjg_modifyItem();
        },
        rowStyler: function (index, row) {
            if (row.sfzx == '是') {
                return 'background-color:rgba(255, 130, 87, 0.64);';
            }
        }
    };
    if (type == 1) {
        var columns = {columns: [
            [
                {field: 'qc', title: '全称', width: 50},
                {field: 'jc', title: '简称', width: 30},
                {field: 'qyfr_qyqc', title: '企业法人', width: 30},
                {field: 'lxr', title: '联系人', width: 30},
                {field: 'zt', title: '状态', width: 30, formatter: formatQyjgSp},
                //     {field:'ysgjList', title:'运输工具识别码', width:40},
                {field: 'bz', title: '备注', width: 60},
                {field: 'sfzx', title: '启用', align: 'center', width: 10, formatter: function (value, row, index) {
                    if (value == '是')
                        return '否';
                    else
                        return '是';
                }}
            ]
        ]}
        options = $.extend(options, columns);
    } else {
        var columns = {columns: [
            [
                {field: 'qc', title: '全称', width: 50},
                {field: 'jc', title: '简称', width: 30},
                {field: 'qyfr_qyqc', title: '企业法人', width: 30},
                {field: 'lxr', title: '联系人', width: 30},
                {field: 'bzjfs', title: '保证金使用方式', width: 20,
                    formatter: function (value) {
                        if (value == '0')
                            return '一次性';
                        if (value == '1')
                            return '按比例';
                    }
                },
                {field: 'bm', title: '编码', width: 30},
                {field: 'zt', title: '状态', width: 30, formatter: formatQyjgSp},
                {field: 'bz', title: '备注', width: 60},
                {field: 'sfzx', title: '启用', align: 'center', width: 10, formatter: function (value, row, index) {
                    if (value == '是')
                        return '否';
                    else
                        return '是';
                }}
            ]
        ]}
        options = $.extend(options, columns);
    }
    return options;
}
//改变状态，启用停用
function changeQyjgState(url, message) {
    var qyjgId = $("#qyjg_grid").datagrid("getSelected").id;
    if (qyjgId) {
        $.messager.confirm("确认", message, function (r) {
            if (r) {
                $.post(url, {'qyjgId': qyjgId}, function (data) {
                    if (data.statusCode == 200) {
                        $('#qyjg_grid').datagrid('reload');
                        $.messager.show({
                            title: '提示框',
                            msg: data.message,
                            timeout: 3000,
                            showType: 'slide'
                        });
                    } else {
                        $.messager.alert('提示', data.message, 'info');
                    }
                })

            }
        })
    }
}

//改变状态，启用停用
function changeQyjgNbgs(url, message) {
    var qyjgId = $("#qyjg_grid").datagrid("getSelected").id;
    if (qyjgId) {
        $.messager.confirm("确认", message, function (r) {
            if (r) {
                $.post(url, {'qyjgId': qyjgId}, function (data) {
                    if (data.statusCode == 200) {
                        $('#qyjg_grid').datagrid('reload');
                        $.messager.show({
                            title: '提示框',
                            msg: data.message,
                            timeout: 3000,
                            showType: 'slide'
                        });
                    } else {
                        $.messager.alert('提示', data.message, 'info');
                    }
                })

            }
        })
    }
}

function formatQyjgSp(val, row) {
    if (!row.processInstanceId) {
        return val;
    } else {
        return '<a href="javascript:viewQyjgFlowPicture();" style="color: red">' + val + '</a>';
    }
}

function viewQyjgFlowPicture() {
    var row = $('#qyjg_grid').datagrid('getSelected');
    $.window({
        title: "流程历史",
        iconCls: 'icon-add2',
        url: $.webPath() + "/flow/publish/flowPicture?processInstanceId=" + encodeURI(encodeURI(row.processInstanceId)) + "&businessNo=" + row.bm,
        width: 650,
        height: 500,
        closed: true,
        modal: true,
        isMax: true
    });
}

function qyjg_fkfs(title) {
    var record = $("#qyjg_grid").datagrid("getSelected");
    if (record == null) {
        $.messager.alert("提示", "请选择要维护的企业机构!", "warning");
        return;
    }
    var href = $.webPath() + "/organ/qyjg/qyjg_fkfs_content?operation=update&qyjgId=" + record.id;
    var actionUrl = $.webPath() + "/organ/qyjg/qyjg_fkfs";
    qyjg_fkfs_showDialog(title, href, actionUrl);
}
//弹框调用方法
function qyjg_fkfs_showDialog(title, href, actionUrl) {
    var win = $.window({
        title: title,
        iconCls: 'icon-add2',
        width: 1024,
        height: 500,
        cache: false,
        url: href,
        modal: true,
        buttons: [
            {
                text: '保存',
                handler: function () {
                    $('#qyjgFkfsForm').form('submit', {
                        url: actionUrl,
                        onSubmit: function (param) {
                            $("#qyjg_fkfs_table").edatagrid('saveRow');
                            var data = $('#qyjg_fkfs_table').edatagrid("getData");
                            var arrayPrefix = 'qyjg.fkfsList';
                            var paramString = "{";
                            for (var i = 0; i < data.rows.length; i++) {
                                if (data.rows[i]['fklx.id'] == null || data.rows[i]['fklx.id'] == '') {
                                    $.messager.alert('提示', '第' + (i + 1) + '行的付款方式不能为空 !', 'info');
                                    return false;
                                }
                                {
                                    var objectString = $.toJSONStringSubPrefix(data.rows[i], arrayPrefix + "[" + i + "].",
                                        [
                                            'id',
                                            'fkll',
                                            'qyjg.id',
                                            'fklx.id',
                                            'fksjStart',
                                            'fksj',
                                            'fkgs'
                                        ]);
                                    paramString = paramString + objectString.substring(1, objectString.length - 1) + ",";
                                }
                            }
                            if (data.rows && data.rows.length > 0)
                                paramString = paramString.substring(0, paramString.length - 1);
                            paramString += "}";
                            $.extend(param, $.parseJSON(paramString));
                            return $(this).form('validate');
                        },
                        success: function (data) {
                            var json = $.parseJSON(data);
                            if (json.statusCode == '200') {
                                $(win).window('close');
                                $.messager.show({
                                    title: '提示',
                                    msg: json.message,
                                    timeout: 3000,
                                    showType: 'slide'
                                });
                            } else
                                $.messager.alert('提示', json.message, 'error');
                        }
                    });
                }
            }
        ]
    });
}

